package com.videohub.videohub.activities;

import androidx.fragment.app.Fragment;
import android.os.Bundle;
import androidx.annotation.NonNull;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import androidx.appcompat.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.TextView;

import com.videohub.videohub.R;
import com.videohub.videohub.Tab.CategoryFragment;
import com.videohub.videohub.Tab.FavFragment;
import com.videohub.videohub.Tab.HomeFragment;
import com.videohub.videohub.Tab.MyFragment;

public class MainTabActivity extends AppCompatActivity {

    private TextView mTextMessage;
    private Fragment[] mFragments;

    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            Fragment f = mFragments[0];
            switch (item.getItemId()) {
                case R.id.navigation_home:
                    f = mFragments[0];
                    break;
                case R.id.navigation_dashboard:
                    f = mFragments[1];
                    break;
                case R.id.navigation_notifications:
                    f = mFragments[2];
                    break;
//                case R.id.navigation_my:
//                    f = mFragments[3];
//                    break;
                }
                getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, f).commit();

            return false;
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_tab);

        mTextMessage = (TextView) findViewById(R.id.message);
        BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

        mFragments = getFragments("from");

        Fragment f = mFragments[0];
        getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, f).commit();

    }

    public  final String []mTabTitle = new String[]{"首页","收藏","分类","我的"};

    public Fragment[] getFragments(String from){
        Fragment fragments[] = new Fragment[4];
        fragments[0] = HomeFragment.newInstance(from, from);
        fragments[1] = CategoryFragment.newInstance(from, from);
        fragments[3] = MyFragment.newInstance(from, from);
//        fragments[2] = new FirstLayerFragment();
        fragments[2] = FavFragment.newInstance(from, from);
//        fragments[3] = .newInstance(from, from);
        return fragments;
    }


}
